package agh.rozproszony;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Konfiguracja aplikacji na podstawie pliku .properties
 */
public class RozproszonyConfiguration {

    /**
     * Sciezka do pliku ustawien programu
     */
    private static final String CONFG_PATH = "config/rozproszony.properties";
    private String rmiReservationServiceAddress;
    private String rmiMessagesServiceAddress;
    private String rmiCodebase;
    private String dbHost;
    private String dbName;
    private String dbUser;
    private String dbPass;

    public RozproszonyConfiguration() {
        load();
    }

    public void load() {
        Properties prop = new Properties();
        try {
            prop.load(new FileInputStream(CONFG_PATH));
        } catch (IOException ex) {
            throw new RuntimeException("Nie mozna odczytac konfiguracji z " + CONFG_PATH, ex);
        }

        rmiReservationServiceAddress = prop.getProperty("rmi_reservation_service_address", "rmi://localhost/ReservationsServer");
        rmiMessagesServiceAddress = prop.getProperty("rmi_messages_service_address", "rmi://localhost/MessagesServer");

        // Domyslny codebase to plik .jar gotowej aplikacji w aktualnym katalogu
        rmiCodebase = prop.getProperty("rmi_codebase", "file:/Rozproszony.jar");

        dbHost = prop.getProperty("dbHost", "localhost");
        dbUser = prop.getProperty("dbUser", "root");
        dbPass = prop.getProperty("dbPass", "pass");
        dbName = prop.getProperty("dbName", "serverdb");

    }

    public void printConfiguration() {
        System.out.println("Adres uslugi rezerwacji RMI: " + rmiReservationServiceAddress);
        System.out.println("Adres uslugi wiadomosci RMI: " + rmiMessagesServiceAddress);
        System.out.println("RMI codebase: " + rmiCodebase);
    }

    public String getRmiReservationServiceAddress() {
        return rmiReservationServiceAddress;
    }

    public String getRmiMessagesServiceAddress() {
        return rmiMessagesServiceAddress;
    }

    public String getRmiCodebase() {
        return rmiCodebase;
    }

    public String getDbHost() {
        return dbHost;
    }

    public String getDbName() {
        return dbName;
    }

    public String getDbUser() {
        return dbUser;
    }

    public String getDbPass() {
        return dbPass;
    }
    
    
}
